from openpyxl import Workbook

data: list = [
    ["标题1", "标题2", "标题3"],
    ["内容1", "内容2", "内容3"],
    ["内容4", "内容5", "内容6"],
]  # 假设有一个二维数组，需要写入到Excel中


newWorkbook = Workbook()  # 创建空工作簿
try:
    targetSheet = newWorkbook.active  # 获取当前活动工作表
    if targetSheet is None:  # 如果当前工作表不存在，则创建一个工作表
        targetSheet = newWorkbook.create_sheet()  # 创建一个新的工作表
    for row in data:  # 遍历数据
        targetSheet.append(row)  # 写入数据
    newWorkbook.save("./output.xlsx")  # 保存工作簿
except Exception as e:
    print(f"发生错误: {e}")
finally:
    newWorkbook.close()
